package cn.hfjava.kz.validator;

import cn.hfjava.kz.common.annotation.Status;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;


import java.util.Arrays;
import java.util.List;

public class StatusValidator implements ConstraintValidator<Status, Integer> {

    private List<String> statusList;

    @Override
    public void initialize(Status ca) {
        this.statusList = Arrays.asList(ca.statusType());
        ConstraintValidator.super.initialize(ca);
    }

    @Override
    public boolean isValid(Integer status, ConstraintValidatorContext constraintValidatorContext) {
       if(status != null) {
           return statusList.contains(status.toString());
       }
       return true;
    }
}
